﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using compshop.Infrastructure.CompShopDataService;

namespace compshop.Modules.ListOfTransportationBills.View
{
    /// <summary>
    /// Логика взаимодействия для AddTransportationBill.xaml
    /// </summary>
    public partial class AddTransportationBill : Window
    {
        public AddTransportationBill()
        {
            InitializeComponent();
            bill = new BillForTransportation();
            btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
            btnOk.Click += new RoutedEventHandler(btnOk_Click);
        }

        void btnOk_Click(object sender, RoutedEventArgs e)
        {
            
            DateTime dateTemp;
            decimal totalTemp;
            bool action = true;
            bool rez = DateTime.TryParse(txbEndDate.Text, out dateTemp);
            action &= rez;
            if (rez)
                bill.EndDate = dateTemp;
            else MessageBox.Show("Дата окончания периода не введена или неправильно введена.");
            rez = DateTime.TryParse(txbStartDate.Text, out dateTemp);
            action &= rez;
            if (rez)
                bill.StartDate = dateTemp;
            else MessageBox.Show("Дата начала периода не введена или неправильно введена.");

            rez = decimal.TryParse(txbTotal.Text, out totalTemp);
            action &= rez;
            if (rez)
                bill.Total = totalTemp;
            else MessageBox.Show("Дата сумма не введена или неправильно введена.");
            if (action)
            {
                DialogResult = true;
                this.Close();
            }
        
        }

        void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }
        public BillForTransportation bill{get;set;}
    }
}
